package com.yy.jhl.ui.manager.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.yy.common.base.BaseActivity;
import com.yy.common.commonutils.SPUtils;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.app.AppConstant;
import com.yy.jhl.bean.InviteBatchInfo;
import com.yy.jhl.bean.InvitePackageInfo;
import com.yy.jhl.ui.manager.adapter.InviteBoxInfoAdapter;
import com.yy.jhl.ui.manager.contract.MainWithCodeContract;
import com.yy.jhl.ui.manager.presenter.MainWithCodePresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by libingn on 2017/12/18.
 */

public class InviteBoxInfoActivity extends BaseActivity<MainWithCodePresenter> implements MainWithCodeContract.View {

    @BindView(R.id.content_parent)
    LinearLayout contentParent;
    @BindView(R.id.order_name_text)
    TextView orderNameText;
    @BindView(R.id.order_code_text)
    TextView orderCodeText;
    @BindView(R.id.order_batch_text)
    TextView orderBatchText;
    @BindView(R.id.order_gys_text)
    TextView orderGysText;
    @BindView(R.id.package_code_text)
    TextView packageCodeText;
    @BindView(R.id.order_time_text)
    TextView orderTimeText;
    @BindView(R.id.listview)
    ListView listview;
    @BindView(R.id.upload_btn)
    Button uploadBtn;
    String boxId = "";
    InviteBoxInfoAdapter inviteBoxInfoAdapter;
    InvitePackageInfo packageInfo;
    private int loginType;
    public static void startAction(Context mContext, String boxId) {
        Intent intent = new Intent(mContext, InviteBoxInfoActivity.class);
        intent.putExtra("boxId", boxId);
        mContext.startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.act_invite_seal_box;
    }

    @Override
    public void initView() {
        loginType = SPUtils.getSharedIntData(mContext, AppConstant.SP_KEY_LOGIN_TYPE);
        if (loginType != 3){
            uploadBtn.setVisibility(View.GONE);
        }
        boxId = getIntent().getStringExtra("boxId");
        showTitle("封箱信息", new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        inviteBoxInfoAdapter = new InviteBoxInfoAdapter(mContext);
        listview.setAdapter(inviteBoxInfoAdapter);
        contentParent.setVisibility(View.GONE);
        mPresenter.getPackageInfo(boxId);
    }

    @Override
    public void getBatchCodeSuccess(InviteBatchInfo inviteBatchInfo) {

    }

    @Override
    public void getBatchCodeFail() {

    }

    @Override
    public void getPackageInfoSuccess(InvitePackageInfo invitePackageInfo) {
        contentParent.setVisibility(View.VISIBLE);
        packageInfo = invitePackageInfo;
        orderNameText.setText(invitePackageInfo.getTitle());
        orderCodeText.setText(invitePackageInfo.getOrder_sn());
        orderBatchText.setText(invitePackageInfo.getBatch_sn());
        orderGysText.setText(invitePackageInfo.getCompany_name());
        packageCodeText.setText("箱号："+invitePackageInfo.getPack_num());
        if (invitePackageInfo.getItems() != null && invitePackageInfo.getItems().size() > 0){
            orderTimeText.setText(invitePackageInfo.getItems() .get(0).getCreate_time());
            inviteBoxInfoAdapter.addAllData(invitePackageInfo.getItems());
        }
    }

    @Override
    public void getPackageInfoFail() {

    }

    @OnClick(R.id.upload_btn)
    public void onViewClicked() {
        if (packageInfo == null){
            showShortToast("数据加载失败！");
            return;
        }
        if ("1".equals(packageInfo.getUpload_completed())){
            showShortToast("本次验货操作已完成！");
            return;
        }
        InviteUploadActivity.startAction(mContext,packageInfo);
        finish();
    }
}
